# Dreams have to come true after all
from flask import Flask

from settings import map_config


def creat_app(config_type):
    app = Flask(__name__)
    # 加载项目的配置
    app.config.from_object(map_config.get(config_type))
    # 加载用户模块
    from Financial.resource.user import user_bp
    app.register_blueprint(user_bp)
    # 加载信息模块
    from Financial.resource.letter import letter_bp
    app.register_blueprint(letter_bp)
    # 加载银行卡模块
    from Financial.resource.card import card_bp
    app.register_blueprint(card_bp)
    # 加载产品模块
    from Financial.resource.product import product_bp
    app.register_blueprint(product_bp)
    # 加载交易模块
    from Financial.resource.transaction import transaction_bp
    app.register_blueprint(transaction_bp)
    # 连接redis
    from comment.utils.financial_redis import redis_client
    redis_client.init_app(app)
    # 连接mysql
    from comment import db
    db.init_app(app)
    # 请求钩子
    from comment.utils.jwt_request import jwt_request_auth
    app.before_request(jwt_request_auth)
    return app

    pass
